#include "config.hpp"
#include "Data_Man.hpp"
#include "Hot_Man.hpp"
#include "Service.hpp"
#include <thread>

cloud::DataManager* data;

void testJsonUtil()
{
    const char *name = "小明";
    const char *school = "xxx学校";
    int age = 18;
    float score[3] = {10.9, 30.9, 50.6};

    Json::Value root;
    root["姓名"] = name;
    root["学校"] = school;
    root["年龄"] = age;
    root["成绩"].append(score[0]);
    root["成绩"].append(score[1]);
    root["成绩"].append(score[2]);

    std::string str;
    cloud::JsonUtil::Serialize(root, &str);
    std::cout << str.c_str() << std::endl;

    cloud::JsonUtil::DeSerialize(str, &root);

    std::cout << root["姓名"].asString() << std::endl;
    std::cout << root["学校"].asString() << std::endl;
    std::cout << root["年龄"].asInt() << std::endl;
    int sz = root["成绩"].size();
    for (int i = 0; i < sz; i++)
    {
        std::cout << root["成绩"][i].asFloat() << std::endl;
    }
}
void testFileUtil()
{
    // colud::FileUtil file(filename);
    // std::cout<<file.FileSize()<<std::endl;
    // std::cout<<file.LastMTime()<<std::endl;
    // std::cout<<file.LastATime()<<std::endl;
    // cloud::FileUtil ifile(filename);
    // std::string body;
    // ifile.GetContent(&body);
    // std::cout<<body.size()<<' '<<ifile.FileSize()<<std::endl;

    // cloud::FileUtil ofile("hello.txt");
    // ofile.SetContent(&body);

    // cloud::FileUtil ifile("bundle.cpp");
    // ifile.Compress("hello1");
    // cloud::FileUtil ofile("hello1");
    // ofile.UnCompress("hello2.txt");

    cloud::FileUtil f("./test");
    f.CreateDirectory();
    std::vector<std::string> v;
    f.ScanDirectory(&v);
    for (auto e : v)
    {
        std::cout << e << std::endl;
    }
    return;
}

void testconfiginstance()
{
    cloud::Config *instance = cloud::Config::Getinstance();
    std::cout << instance->Get_hot_time() << std::endl;
    std::cout << instance->Get_server_port() << std::endl;
    std::cout << instance->Get_server_ip() << std::endl;
}

void testdatamanager()
{
    // cloud::Backupinfo bi;
    // bi.NewBackupinfo("../云备份项目/bundle.cpp");
    // std::cout<<bi._pack_flag<<std::endl;
    // std::cout<<bi._fsize<<std::endl;
    // std::cout<<bi._atime<<std::endl;
    // std::cout<<bi._mtime<<std::endl;
    // std::cout<<bi._real_path<<std::endl;
    // std::cout<<bi._pack_path<<std::endl;
    // std::cout<<bi._url_path<<std::endl;
    // cloud::Backupinfo bi2;
    // bi2.NewBackupinfo("../云备份项目/bundle.h");

    // cloud::Backupinfo bi3;
    // bi3.NewBackupinfo("../云备份项目/Data_Man.hpp");
    // cloud::DataManager dm;
    // dm.insert(bi);
    // dm.insert(bi2);
    // dm.insert(bi3);

    cloud::DataManager dm;
    std::vector<cloud::Backupinfo> arr;
    dm.GetAll(&arr);
    for (auto bi : arr)
    {
        std::cout << bi._pack_flag << std::endl;
        std::cout << bi._fsize << std::endl;
        std::cout << bi._atime << std::endl;
        std::cout << bi._mtime << std::endl;
        std::cout << bi._real_path << std::endl;
        std::cout << bi._pack_path << std::endl;
        std::cout << bi._url_path << std::endl;
        std::cout << std::endl;
    }
}


void testhotmanager()
{
    //data = new cloud::DataManager;
    cloud::Hot_Manager hot;
    hot.RunMoudle();
    
}


void testservice()
{
    //data = new cloud::DataManager;
    cloud::Service service;
    service.run();
}

int main(int argc, char *argv[])
{
    // testFileUtil();
    // testJsonUtil();
    // testconfiginstance();
    //testdatamanager();
    //testhotmanager();
    data = new cloud::DataManager;
    std::thread svr(testservice);
    std::thread hotman(testhotmanager);
    svr.join();
    hotman.join();
    return 0;
}